home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cgazv5n5.arc / LIST7.C < prev    next >
C/C++ Source or Header  |  1991-09-23  |  1KB  |  48 lines

  1. /*---------------------------------------- Listing 7 ------
  2.  * Demonstration of assert().
  3.  * See Listing 1 for copyright terms.
  4.  *-------------------------------------------------------*/
  5. #include <stdio.h>
  6. #include <signal.h>
  7.  
  8. /*---------------------------------------------------------
  9.  * If the following line is un-commented, assert will 
  10.  * cease to function.
  11.  *-------------------------------------------------------*/
  12.  
  13. /* #define NDEBUG  */
  14. #include <assert.h>
  15.  
  16. void main ( void );
  17. void Write ( FILE *Handle, char String[] );
  18. void SigHndlr ( int Signal, int SubCode );
  19.  
  20. void main()
  21. {
  22.     signal ( SIGABRT, SigHndlr );
  23.  
  24.     /*---------------------------------------------------------
  25.      * Some poor soul doesn't understand Write()'s 
  26.      * parameter requirements.
  27.      *-------------------------------------------------------*/
  28.  
  29.     Write ( NULL, "Top of File\n" );
  30. }
  31.  
  32.  
  33. void Write ( FILE *Handle, char String[] )
  34. {
  35.     /* Make sure we're getting valid parameters! */
  36.  
  37.     assert ( String != NULL );
  38.     assert ( Handle != NULL );
  39.  
  40.     fprintf ( Handle, "%s\n", String );
  41. }
  42.  
  43.  
  44. void SigHndlr ( int Signal, int SubCode )
  45. {
  46.     fprintf ( stderr, "Signal %d, %d raised\n", 
  47.               Signal, SubCode );
  48. }